package com.sumainfor.pc.market.controller.gmio;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.market.service.gmio.PactGmioService;
import com.sumainfor.pc.market.service.tenant.impl.TenHouService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 运营部调用
 * <p>
 *
 * @author: zc
 * @create: 2019-11-14 16:28
 **/
@Controller
@RequestMapping("/key/PactGmio")
public class PactGmioController {
    @Autowired
    PactGmioService pactGmioService;

    @Autowired
    TenHouService tenHouService;



    /**
     * 根据房源详表标号查询是否存在智能电表
     * @param params
     * @return
     */
    @ResponseBody
    @GetMapping("/getHouInfoPayment")
    public JsonResult getHouInfoPayment(@RequestParam Map<String,Object> params){
        return pactGmioService.getHouInfoPayment(params);
    }

    /**
     * 根据房源编号查询该房源下的房间编号
     * @param params
     * @return
     */
    @ResponseBody
    @GetMapping("/getHouInfoNum")
    public List<Map<String,Object>> getHouInfoNum(@RequestParam Map<String,Object> params){
        return pactGmioService.getHouInfoNum(params);
    }

    /**
     * 根据房源编号查询该房源下的在租合同
     * @param params
     * @return
     */
    @ResponseBody
    @GetMapping("/getHouPact")
    public List<Map<String,Object>> getHouPact(@RequestParam Map<String,Object> params){
        return pactGmioService.getHouPact(params);
    }

    /**
     * 查询在租中,整租or合租 智能or非智能的房源
     * @param params
     * @param pager
     * @return
     */
    @ResponseBody
    @PostMapping("/getPactNumHou")
    public JsonResult getPactNumHou(@RequestBody Map<String,Object> params, Pager pager){
        pager.setPageno(Integer.parseInt(params.get("pageno").toString()));
        pager.setPagesize(Integer.parseInt(params.get("pagesize").toString()));
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer count = pactGmioService.getPactNumHouCount(params);
        if (count==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,count);
        }else {
            List<Map<String,Object>> getPactNumHou=pactGmioService.getPactNumHou(params);
            return pageUtils.getJsonResult(getPactNumHou, params, count);
        }
    }

    /**
     * 秘书抄表房源
     */
    @ResponseBody
    @PostMapping("/getHouId")
    public JsonResult getHouId(@RequestBody Map<String,Object> params, Pager pager){
        pager.setPageno(Integer.parseInt(params.get("pageno").toString()));
        pager.setPagesize(Integer.parseInt(params.get("pagesize").toString()));
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer count = pactGmioService.getHouIdCount(params);
        if (count==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,count);
        }else {
            List<Map<String,Object>> getPactNumHou=pactGmioService.getHouId(params);
            return pageUtils.getJsonResult(getPactNumHou, params, count);
        }
    }

    /**
     * 查询当前房间是否已出租
     * @param params
     * @return
     */
    @ResponseBody
    @PostMapping("/getInfoStatus")
    public JsonResult getInfoStatus(@RequestBody Map<String,Object> params){
        System.out.println(params);
        JsonResult result = new JsonResult();
        return result.put(pactGmioService.getInfoStatus(params));

    }

    /**
     * 查询房源签署公司
     * @param params
     * @return
     */
    @ResponseBody
    @PostMapping("/getCorId")
    public JsonResult getCorId(@RequestBody Map<String,Object> params){
        JsonResult result = new JsonResult();
        return result.put(pactGmioService.getCorId(params));
    }

    /**
     * 根据合同编号获取在租房间的智能门锁的情况
     * @param params
     * @return
     */
    @ResponseBody
    @PostMapping("/getIntelligentRoom")
    public JsonResult getIntelligentRoom(@RequestBody Map<String,Object> params){
        JsonResult result = new JsonResult();
        return result.put(tenHouService.getIntelligentRoom(params));
    }


}
